home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / c / stormamiga_lib-v45_00d / stormc_v3-examples / special / dhrystone / dhry_stormamiga_1.c < prev    next >
C/C++ Source or Header  |  2000-02-28  |  10KB  |  342 lines

  1. /*
  2.  ****************************************************************************
  3.  *
  4.  *                   "DHRYSTONE" Benchmark Program
  5.  *                   -----------------------------
  6.  *
  7.  *  Version:    C, Version 2.1
  8.  *
  9.  *  File:       dhry_1.c (part 2 of 3)
  10.  *
  11.  *  Date:       May 25, 1988
  12.  *
  13.  *  Author:     Reinhold P. Weicker
  14.  *
  15.  ****************************************************************************
  16.  */
  17.  
  18. #define STORMAMIGA_NOWB
  19. #include <stormamiga.h>
  20.  
  21. #include "dhry.h"
  22.  
  23. void Proc_1();
  24. void Proc_2();
  25. void Proc_3();
  26. void Proc_4();
  27. void Proc_5();
  28. Proc_6();
  29. Proc_7();
  30. Proc_8();
  31. Func_2();
  32.  
  33.  
  34. /* Global Variables: */
  35.  
  36. Rec_Pointer     Ptr_Glob,
  37.         Next_Ptr_Glob;
  38. int             Int_Glob;
  39. Boolean         Bool_Glob;
  40. char            Ch_1_Glob,
  41.         Ch_2_Glob;
  42. int             Arr_1_Glob [50];
  43. int             Arr_2_Glob [50] [50];
  44.  
  45. /* extern char     *malloc (); */
  46. Enumeration     Func_1 ();
  47.   /* forward declaration necessary since Enumeration may not simply be int */
  48.  
  49. #ifndef REG
  50.     Boolean Reg = false;
  51. #define REG
  52.     /* REG becomes defined as empty */
  53.     /* i.e. no register variables   */
  54. #else
  55.     Boolean Reg = true;
  56. #endif
  57.  
  58. /* variables for time measurement: */
  59.  
  60.  
  61. /* extern long     time(); */
  62.         /* see library function "time"  */
  63. #define Too_Small_Time 2
  64.         /* Measurements should last at least 2 seconds */
  65.  
  66. long            Begin_Time,
  67.         End_Time,
  68.         User_Time;
  69. double          Microseconds,
  70.         Dhrystones_Per_Second;
  71.  
  72. /* end of variables for time measurement */
  73.  
  74.  
  75. int main__ (void)
  76. /*****/
  77.  
  78.   /* main program, corresponds to procedures        */
  79.   /* Main and Proc_0 in the Ada version             */
  80. {
  81.     One_Fifty       Int_1_Loc;
  82.   REG   One_Fifty       Int_2_Loc;
  83.     One_Fifty       Int_3_Loc;
  84.   REG   char            Ch_Index;
  85.     Enumeration     Enum_Loc;
  86.     Str_30          Str_1_Loc;
  87.     Str_30          Str_2_Loc;
  88.   REG   int             Run_Index;
  89.   REG   int             Number_Of_Runs;
  90.  
  91.   /* Initializations */
  92.  
  93.   Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  94.   Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  95.  
  96.   Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
  97.   Ptr_Glob->Discr                       = Ident_1;
  98.   Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
  99.   Ptr_Glob->variant.var_1.Int_Comp      = 40;
  100.   strcpy (Ptr_Glob->variant.var_1.Str_Comp,
  101.       "DHRYSTONE PROGRAM, SOME STRING");
  102.   strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
  103.  
  104.   Arr_2_Glob [8][7] = 10;
  105.     /* Was missing in published program. Without this statement,    */
  106.     /* Arr_2_Glob [8][7] would have an undefined value.             */
  107.     /* Warning: With 16-Bit processors and Number_Of_Runs > 32000,  */
  108.     /* overflow may occur for this array element.                   */
  109.  
  110.   printf ("\nDhrystone Benchmark, Version 2.1 (Language: C)\n\n");
  111.   if (Reg)
  112.   {
  113.     printf ("Program compiled with 'register' attribute\n\n");
  114.   }
  115.   else
  116.   {
  117.     printf ("Program compiled without 'register' attribute\n\n");
  118.   }
  119.   printf ("Please give the number of runs through the benchmark: ");
  120.   {
  121.     int n;
  122.     scanf_ ("%d", &n);
  123.     Number_Of_Runs = n;
  124.   }
  125.   printf ("\nExecution starts, %d runs through Dhrystone\n", Number_Of_Runs);
  126.  
  127.   /***************/
  128.   /* Start timer */
  129.   /***************/
  130.  
  131.   Begin_Time = time ( (time_t *) 0);
  132.  
  133.   for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
  134.   {
  135.  
  136.     Proc_5();
  137.     Proc_4();
  138.       /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
  139.     Int_1_Loc = 2;
  140.     Int_2_Loc = 3;
  141.     strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  142.     Enum_Loc = Ident_2;
  143.     Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
  144.       /* Bool_Glob == 1 */
  145.     while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
  146.     {
  147.       Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
  148.     /* Int_3_Loc == 7 */
  149.       Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
  150.     /* Int_3_Loc == 7 */
  151.       Int_1_Loc += 1;
  152.     } /* while */
  153.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  154.     Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
  155.       /* Int_Glob == 5 */
  156.     Proc_1 (Ptr_Glob);
  157.     for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
  158.                  /* loop body executed twice */
  159.     {
  160.       if (Enum_Loc == Func_1 (Ch_Index, 'C'))
  161.       /* then, not executed */
  162.     {
  163.     Proc_6 (Ident_1, &Enum_Loc);
  164.     strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
  165.     Int_2_Loc = Run_Index;
  166.     Int_Glob = Run_Index;
  167.     }
  168.     }
  169.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  170.     Int_2_Loc = Int_2_Loc * Int_1_Loc;
  171.     Int_1_Loc = Int_2_Loc / Int_3_Loc;
  172.     Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
  173.       /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
  174.     Proc_2 (&Int_1_Loc);
  175.       /* Int_1_Loc == 5 */
  176.  
  177.   } /* loop "for Run_Index" */
  178.  
  179.   /**************/
  180.   /* Stop timer */
  181.   /**************/
  182.  
  183.   End_Time = time ( (time_t *) 0);
  184.  
  185.   printf ("Execution ends\n\n");
  186.   printf ("Final values of the variables used in the benchmark:\n\n");
  187.   printf ("Int_Glob:            %d\n", Int_Glob);
  188.   printf ("        should be:   %d\n", 5);
  189.   printf ("Bool_Glob:           %d\n", Bool_Glob);
  190.   printf ("        should be:   %d\n", 1);
  191.   printf ("Ch_1_Glob:           %c\n", Ch_1_Glob);
  192.   printf ("        should be:   %c\n", 'A');
  193.   printf ("Ch_2_Glob:           %c\n", Ch_2_Glob);
  194.   printf ("        should be:   %c\n", 'B');
  195.   printf ("Arr_1_Glob[8]:       %d\n", Arr_1_Glob[8]);
  196.   printf ("        should be:   %d\n", 7);
  197.   printf ("Arr_2_Glob[8][7]:    %d\n", Arr_2_Glob[8][7]);
  198.   printf ("        should be:   Number_Of_Runs + 10\n");
  199.   printf ("Ptr_Glob->\n");
  200.   printf ("  Ptr_Comp:          %d\n", (int) Ptr_Glob->Ptr_Comp);
  201.   printf ("        should be:   (implementation-dependent)\n");
  202.   printf ("  Discr:             %d\n", Ptr_Glob->Discr);
  203.   printf ("        should be:   %d\n", 0);
  204.   printf ("  Enum_Comp:         %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
  205.   printf ("        should be:   %d\n", 2);
  206.   printf ("  Int_Comp:          %d\n", Ptr_Glob->variant.var_1.Int_Comp);
  207.   printf ("        should be:   %d\n", 17);
  208.   printf ("  Str_Comp:          %s\n", Ptr_Glob->variant.var_1.Str_Comp);
  209.   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
  210.   printf ("Next_Ptr_Glob->\n");
  211.   printf ("  Ptr_Comp:          %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
  212.   printf ("        should be:   (implementation-dependent), same as above\n");
  213.   printf ("  Discr:             %d\n", Next_Ptr_Glob->Discr);
  214.   printf ("        should be:   %d\n", 0);
  215.   printf ("  Enum_Comp:         %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
  216.   printf ("        should be:   %d\n", 1);
  217.   printf ("  Int_Comp:          %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
  218.   printf ("        should be:   %d\n", 18);
  219.   printf ("  Str_Comp:          %s\n",
  220.                 Next_Ptr_Glob->variant.var_1.Str_Comp);
  221.   printf ("        should be:   DHRYSTONE PROGRAM, SOME STRING\n");
  222.   printf ("Int_1_Loc:           %d\n", Int_1_Loc);
  223.   printf ("        should be:   %d\n", 5);
  224.   printf ("Int_2_Loc:           %d\n", Int_2_Loc);
  225.   printf ("        should be:   %d\n", 13);
  226.   printf ("Int_3_Loc:           %d\n", Int_3_Loc);
  227.   printf ("        should be:   %d\n", 7);
  228.   printf ("Enum_Loc:            %d\n", Enum_Loc);
  229.   printf ("        should be:   %d\n", 1);
  230.   printf ("Str_1_Loc:           %s\n", Str_1_Loc);
  231.   printf ("        should be:   DHRYSTONE PROGRAM, 1'ST STRING\n");
  232.   printf ("Str_2_Loc:           %s\n", Str_2_Loc);
  233.   printf ("        should be:   DHRYSTONE PROGRAM, 2'ND STRING\n\n");
  234.  
  235.   User_Time = End_Time - Begin_Time;
  236.  
  237.   if (User_Time < Too_Small_Time)
  238.   {
  239.     printf ("Measured time too small to obtain meaningful results\n");
  240.     printf ("Please increase number of runs\n\n");
  241.   }
  242.   else
  243.   {
  244.     Microseconds = (double) User_Time * Mic_secs_Per_Second
  245.             / (double) Number_Of_Runs;
  246.     Dhrystones_Per_Second = (double) Number_Of_Runs / (double) User_Time;
  247.     printf ("Microseconds for one run through Dhrystone: %6.6g \n", Microseconds);
  248.     printf ("Dhrystones per Second:                      %6.6g \n\n", Dhrystones_Per_Second);
  249.   }
  250. return NULL;
  251. }
  252.  
  253.  
  254. void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
  255. /******************/
  256.  
  257.   /* executed once */
  258. {
  259.   REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
  260.                     /* == Ptr_Glob_Next */
  261.   /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
  262.   /* corresponds to "rename" in Ada, "with" in Pascal           */
  263.  
  264.   structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
  265.   Ptr_Val_Par->variant.var_1.Int_Comp = 5;
  266.   Next_Record->variant.var_1.Int_Comp
  267.     = Ptr_Val_Par->variant.var_1.Int_Comp;
  268.   Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
  269.   Proc_3 (&Next_Record->Ptr_Comp);
  270.     /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
  271.             == Ptr_Glob->Ptr_Comp */
  272.   if (Next_Record->Discr == Ident_1)
  273.     /* then, executed */
  274.   {
  275.     Next_Record->variant.var_1.Int_Comp = 6;
  276.     Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
  277.        &Next_Record->variant.var_1.Enum_Comp);
  278.     Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
  279.     Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
  280.        &Next_Record->variant.var_1.Int_Comp);
  281.   }
  282.   else /* not executed */
  283.     structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
  284. } /* Proc_1 */
  285.  
  286.  
  287. void Proc_2 (One_Fifty *Int_Par_Ref)
  288. /******************/
  289.     /* executed once */
  290.     /* *Int_Par_Ref == 1, becomes 4 */
  291.  
  292. {
  293.   One_Fifty  Int_Loc;
  294.   Enumeration   Enum_Loc;
  295.  
  296.   Int_Loc = *Int_Par_Ref + 10;
  297.   do /* executed once */
  298.     if (Ch_1_Glob == 'A')
  299.       /* then, executed */
  300.     {
  301.       Int_Loc -= 1;
  302.       *Int_Par_Ref = Int_Loc - Int_Glob;
  303.       Enum_Loc = Ident_1;
  304.     } /* if */
  305.   while (Enum_Loc != Ident_1); /* true */
  306. } /* Proc_2 */
  307.  
  308.  
  309. void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
  310. /******************/
  311.     /* executed once */
  312.     /* Ptr_Ref_Par becomes Ptr_Glob */
  313.  
  314. {
  315.   if (Ptr_Glob != NULL)
  316.     /* then, executed */
  317.     *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
  318.   Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
  319. } /* Proc_3 */
  320.  
  321.  
  322. void Proc_4 () /* without parameters */
  323. /*******/
  324.     /* executed once */
  325. {
  326.   Boolean Bool_Loc;
  327.  
  328.   Bool_Loc = Ch_1_Glob == 'A';
  329.   Bool_Glob = Bool_Loc | Bool_Glob;
  330.   Ch_2_Glob = 'B';
  331. } /* Proc_4 */
  332.  
  333.  
  334. void Proc_5 () /* without parameters */
  335. /*******/
  336.     /* executed once */
  337. {
  338.   Ch_1_Glob = 'A';
  339.   Bool_Glob = false;
  340. } /* Proc_5 */
  341.  
  342.